package com.cards_game.simple_ddz.rule;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.cards_game.simple_ddz.bean.BaseCardBean;
import com.cards_game.simple_ddz.bean.KingCardBean;
import com.cards_game.simple_ddz.constants.CardConstants.Joker;
import com.cards_game.simple_ddz.constants.CardConstants.Suits;


/**
 * 基础校验
 * 
 * @author 郭国辉
 *
 *         2016年2月14日 下午2:39:02
 */
public abstract class BaseVerify {

	/**
	 * 判断牌面数字是否相等的
	 * 
	 * @param baseCardBean
	 * @return
	 */
	public boolean numIsEquivalent(List<BaseCardBean> baseCardBeans) {
		int num = -1;
		for (BaseCardBean bcb : baseCardBeans) {
			if (num == -1) {
				num = bcb.getNum();
			} else {
				if (num != bcb.getNum()) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * 判断牌面花色是否相同的
	 * 
	 * @param baseCardBean
	 * @return
	 */
	public boolean colorIsSame(List<BaseCardBean> baseCardBeans) {
		Suits s=null;
		for (BaseCardBean bcb : baseCardBeans) {
			if (s==null) {
				s = bcb.getSuit();
			} else {
				if (s!=bcb.getSuit()) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * 判断是否同为大王或小王
	 * 
	 * @param intactCardBean
	 * @return
	 */
	public boolean kingIsSame(List<KingCardBean> kingCardBeans) {
		Joker j=null;
		for (KingCardBean kcb : kingCardBeans) {
			if (j==null) {
				j = kcb.getJoker();
			} else {
				if (j!=kcb.getJoker()) {
					return false;
				}
			}
		}
		return true;
	}
	/**
	 * 是否为王
	 * 
	 * @param intactCardBean
	 * @return
	 */
	public boolean isKing(List<BaseCardBean> bcbs) {
		for (BaseCardBean bcb : bcbs) {
			if (!(bcb instanceof KingCardBean)) {
				return false;
			}
		}
		return true;
	}
	/**
	 * 判断出牌是否是连续的
	 * 
	 * @param baseCardBeans
	 * @return
	 */
	public boolean isSerial(Set<Integer> numSet) {
		if (numSet != null && numSet.size() != 0) {
			Iterator<Integer> it = numSet.iterator();
			int start = it.next();
			while (it.hasNext()) {
				if (start + 1 != it.next()) {
					start = it.next();
					return false;
				}
			}
		}
		return true;
	}
}
